package com.gxa.order.service.impl;/*
 *Created by${妄也} on 2022/10/8
 */

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.gxa.common.commons.R;
import com.gxa.order.controller.xiaoxi;
import com.gxa.order.mapper.xiaoxiMapper;
import com.gxa.order.pojo.OrderFormTz;
import com.gxa.order.service.xiaoxiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;

@Service
public class xiaoxiImpl implements xiaoxiService {
@Autowired(required = false)
private xiaoxiMapper xiaoxiMapper;

    @Override
    public R addA1(OrderFormTz orderFormTz) {

        R r = new R();
        String a="您的订单号为"+orderFormTz.getOrderId()+"的住宿订单，提醒您，请按时入住酒店/民宿；";
        orderFormTz.setNewsData(a);
        TimeZone timeZone = TimeZone.getTimeZone("GMT+8");
        TimeZone.setDefault(timeZone);

        //获取当前时间
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String format = simpleDateFormat.format(date);
        orderFormTz.setStartDate(format);
        try{
            int insert = xiaoxiMapper.insert(orderFormTz);
            r.setCode(200);
            r.setMsg("增加成功");
        }catch (Exception e){
            r.setCode(500);
            r.setMsg("失败");
        }
        return r;
    }

    @Override
    public R addA2(OrderFormTz orderFormTz) {
        R r = new R();
        String a ="";
        if (orderFormTz.getNewsData().equals("1")) {
             a = "您的订单号为" + orderFormTz.getOrderId() + "的服务订单，服务已暂停，如需开启请联系客服顾问；";
        }else {
             a = "您的订单号为" + orderFormTz.getOrderId() + "的服务订单，服务已开启，请及时关注订单动态；";
        }
        orderFormTz.setNewsData(a);
        TimeZone timeZone = TimeZone.getTimeZone("GMT+8");
        TimeZone.setDefault(timeZone);
        //获取当前时间
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String format = simpleDateFormat.format(date);
        orderFormTz.setStartDate(format);
        try{
            int insert = xiaoxiMapper.insert(orderFormTz);
            r.setCode(200);
            r.setMsg("增加成功");
        }catch (Exception e){
            r.setCode(500);
            r.setMsg("失败");
        }
        return r;
    }

    @Override
    public R addA3(OrderFormTz orderFormTz) {
        R r = new R();
        String a ="";
        if (orderFormTz.getNewsData().equals("1")) {
            a = "您的订单号为" + orderFormTz.getOrderId() + "的住宿订单，已提交的申请退款审核已通过，我们会在3到6个工作日内为您打款，请您耐心等待，如有不便请您谅解；";
        }else {
            a = "您的订单号为" + orderFormTz.getOrderId() + "的住宿订单，已提交的申请退款审核未通过，";
        }
        orderFormTz.setNewsData(a);
        TimeZone timeZone = TimeZone.getTimeZone("GMT+8");
        TimeZone.setDefault(timeZone);
        //获取当前时间
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String format = simpleDateFormat.format(date);
        orderFormTz.setStartDate(format);
        try{
            int insert = xiaoxiMapper.insert(orderFormTz);
            r.setCode(200);
            r.setMsg("增加成功");
        }catch (Exception e){
            r.setCode(500);
            r.setMsg("失败");
        }
        return r;
    }

    @Override
    public R addA4(OrderFormTz orderFormTz) {
        R r = new R();
        String a ="";
            a = "您的订单号为" + orderFormTz.getOrderId() + "的住宿订单，已提交退款申请，请耐心等待后台审核；";

        orderFormTz.setNewsData(a);
        TimeZone timeZone = TimeZone.getTimeZone("GMT+8");
        TimeZone.setDefault(timeZone);
        //获取当前时间
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String format = simpleDateFormat.format(date);
        orderFormTz.setStartDate(format);
        try{
            int insert = xiaoxiMapper.insert(orderFormTz);
            r.setCode(200);
            r.setMsg("增加成功");
        }catch (Exception e){
            r.setCode(500);
            r.setMsg("失败");
        }
        return r;
    }

    @Override
    public R addA5(OrderFormTz orderFormTz) {
        R r = new R();
        String a ="";
        a = "您有一个订单号为"+orderFormTz.getOrderId()+"的住宿订单退款审核未通过;/n " +
                "原因：原因原因原因原因原因原因原因原因原因原因原因原因原因原因原因原因原因原因原因原因原因原因原因";

        orderFormTz.setNewsData(a);
        TimeZone timeZone = TimeZone.getTimeZone("GMT+8");
        TimeZone.setDefault(timeZone);
        //获取当前时间
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String format = simpleDateFormat.format(date);
        orderFormTz.setStartDate(format);
        try{
            int insert = xiaoxiMapper.insert(orderFormTz);
            r.setCode(200);
            r.setMsg("增加成功");
        }catch (Exception e){
            r.setCode(500);
            r.setMsg("失败");
        }
        return r;
    }

    @Override
    public R findTZ(String username) {
        UpdateWrapper updateWrapper = new UpdateWrapper();
        updateWrapper.eq("username",username);
        List list = xiaoxiMapper.selectList(updateWrapper);
        R r = new R();
        r.setCode(200);
        r.setMsg("查询成功");
        r.setData(list);
        return r;
    }

    @Override
    public R updata(String id) {
        UpdateWrapper updateWrapper = new UpdateWrapper();
        updateWrapper.eq("id", id);
        OrderFormTz orderFormTz = new OrderFormTz();
        orderFormTz.setRead1(1);
        int update = xiaoxiMapper.update(orderFormTz, updateWrapper);
        R r = new R();
        r.setCode(200);
        r.setMsg("修改成功");
        return r;
    }


}
